package com.example.demo.message;

import org.junit.Test;
import org.springframework.boot.configurationprocessor.json.JSONObject;

import java.util.HashMap;

public class MessageTemplate {
    /**
     * 阿里云短信模板群发（手机号、短信标签、参数）
     */
    @Test
    public void AlySms(){
        StringBuffer phone = new StringBuffer();
        StringBuffer signName = new StringBuffer();
        StringBuffer params = new StringBuffer();
        String[] mobile = {"1234","5678"};
        HashMap<String, String> map = new HashMap<>();
        map.put("code1","1234");
        map.put("code2","5678");
        JSONObject fromObject = new JSONObject(map);
        phone.append("[");
        signName.append("[");
        params.append("[");
        for (int i = 0; i < mobile.length; i++) {
            if(i!=mobile.length-1){
                phone.append("\"").append(mobile[i]).append("\"").append(",");
                signName.append("\"").append("校园招聘系统毕设").append("\"").append(",");
                params.append(fromObject).append(",");
            }else{
                phone.append("\"").append(mobile[i]).append("\"");
                signName.append("\"").append("校园招聘系统毕设").append("\"");
                params.append(fromObject);
            }
        }
        phone.append("]");
        signName.append("]");
        params.append("]");
        System.out.println(phone.toString());
        System.out.println(signName.toString());
        System.out.println(params.toString());
    }


    /**
     * 阿里云短信模板（手机号）
     */
    @Test
    public void AlyPhone() {
        String s = "1234,3434";
        String[] split = s.split(",");
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        for (int i = 0; i < split.length; i++) {
            if(i!= split.length-1){
                sb.append("\"").append(split[i]).append("\"").append(",");
            }else{
                sb.append("\"").append(split[i]).append("\"");
            }
        }
        sb.append("]");
        System.out.println(sb.toString());
        //["1234","3434"]
    }
}
